/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.ad.entity;

import com.jeesite.common.lang.StringUtils;
import org.hibernate.validator.constraints.Length;
import java.util.Date;

import javax.validation.Valid;

import com.jeesite.common.mybatis.annotation.JoinTable;
import com.jeesite.common.mybatis.annotation.JoinTable.Type;
import com.fasterxml.jackson.annotation.JsonFormat;

import com.jeesite.common.entity.DataEntity;
import com.jeesite.common.mybatis.annotation.Column;
import com.jeesite.common.mybatis.annotation.Table;
import com.jeesite.common.mybatis.mapper.query.QueryType;
import com.jeesite.common.utils.excel.annotation.ExcelField;
import com.jeesite.common.utils.excel.annotation.ExcelFields;
import com.jeesite.common.utils.excel.annotation.ExcelField.Align;
import com.jeesite.modules.ad.utils.excel.fieldtype.IndustryType;

/**
 * 广告获客Entity
 * @author Liu,Wenzhao
 * @version 2019-04-17
 */
@Table(name="ad_guest", alias="a", columns={
		@Column(name="id", attrName="id", label="编号", isPK=true),
		@Column(name="ad_id", attrName="adId", label="广告id", isUpdate=false, isQuery=false),
		@Column(name="ad_vertiser_id", attrName="adVertiserId", label="广告主", isUpdate=false),
		@Column(name="mobile", attrName="mobile", label="联系电话", isUpdate=false),
		@Column(name="mobile_location", attrName="mobileLocation", label="号码归属", isUpdate=false),
		@Column(name="sex", attrName="sex", label="性别", isUpdate=false),
		@Column(name="mobile_kind", attrName="mobileKind", label="手机型号", isUpdate=false),
		@Column(name="age", attrName="age", label="年龄", isUpdate=false),
		@Column(name="career", attrName="career", label="职业", isUpdate=false),
		@Column(name="come_from", attrName="comeFrom", label="渠道来源", isUpdate=false),
		@Column(name="guest_time", attrName="guestTime", label="获取时间", isUpdate=false),
		@Column(includeEntity=DataEntity.class),
		@Column(name="ad_name", attrName="adName", label="广告名称", isUpdate=false, queryType=QueryType.LIKE),
		@Column(name="valid_status", attrName="validStatus", label="有效性"),
		@Column(name="consumption_status", attrName="consumptionStatus", label="消费"),
		@Column(name="media_url", attrName="mediaUrl", label="媒体页URL"),
		@Column(name="media_ad_id", attrName="mediaAdId", label="媒体广告位ID"),
		@Column(name="to_ground_url", attrName="toGroundUrl", label="落地页URL"),
		@Column(name="stop_time", attrName="stopTime", label="停留时间", comment="停留时间（秒）"),
		@Column(name="message", attrName="message", label="留言内容"),
	}, joinTable= {
		@JoinTable(type = JoinTable.Type.LEFT_JOIN, entity = Ad.class, attrName = "ad", alias = "u10",
				on = "u10.id = a.ad_id", columns = {
				@Column(name = "id", label = "ID", isPK = true),
				@Column(name = "name", label = "广告名称", isQuery = true, queryType=QueryType.LIKE),
		}),
		@JoinTable(type = JoinTable.Type.LEFT_JOIN, entity = AdVertiser.class, attrName = "adVertiser", alias = "u11",
		on = "u11.id = a.ad_vertiser_id", columns = {
			@Column(name = "id", label = "ID", isPK = true),
			@Column(name = "account", label = "账户名称", isQuery = true, queryType=QueryType.EQ),
			@Column(name = "agent_Id", label = "代理商", isQuery = true, queryType=QueryType.EQ),
		}),
	}, orderBy="a.update_date DESC"
)
public class AdGuest extends DataEntity<AdGuest> {

	@Valid
	@ExcelFields({
		@ExcelField(title="联系电话", attrName="mobile", align=Align.CENTER, sort=10),
		@ExcelField(title="号码归属", attrName="mobileLocation", align=Align.CENTER, sort=20),
		@ExcelField(title="手机型号", attrName="mobileKind", align=Align.CENTER, sort=30),
		@ExcelField(title="性别", attrName="sex", align=Align.LEFT, sort=40, dictType = "sys_user_sex"),
		@ExcelField(title="年龄", attrName="age", align=Align.CENTER, sort=50),
		@ExcelField(title="职业", attrName="career", align=Align.CENTER, sort=60),
		@ExcelField(title="广告主", attrName="adVertiser.account", align = Align.CENTER, sort=70),
		@ExcelField(title="广告计划名称", attrName="ad.name", align=Align.CENTER, sort=80),
		@ExcelField(title="投放媒体", attrName="comeFrom", align=Align.CENTER, sort=90),
		@ExcelField(title="媒体页URL", attrName="mediaUrl", align=Align.CENTER, sort=100),
		@ExcelField(title="广告位ID", attrName="mediaAdId", align=Align.CENTER, sort=110),
		@ExcelField(title="落地页URL", attrName="toGroundUrl", align=Align.CENTER, sort=120),
		@ExcelField(title = "获客时间", attrName = "guestTime", align = Align.CENTER, sort = 130, dataFormat = "yyyy-MM-dd"), 
		@ExcelField(title="停留时间（秒）", attrName="stopTime", align=Align.CENTER, sort=140),
		@ExcelField(title="留言内容", attrName="message", align=Align.CENTER, sort=150),
		@ExcelField(title="有效性", attrName="validStatus", align=Align.CENTER, sort=160, dictType = "guest_status"),
		@ExcelField(title = "备注信息", attrName = "remarks", align = Align.CENTER, sort = 170, type=ExcelField.Type.EXPORT),
		@ExcelField(title = "创建时间", attrName = "createDate", align = Align.CENTER, sort = 180, dataFormat = "yyyy-MM-dd", type=ExcelField.Type.EXPORT), 
		@ExcelField(title = "修改时间", attrName = "updateDate", align = Align.CENTER, sort = 190, dataFormat = "yyyy-MM-dd", type=ExcelField.Type.EXPORT),
	})
	private static final long serialVersionUID = 1L;
	private String adId;		// 广告id
	private String adVertiserId;		// 广告主
	private String mobile;		// 联系电话
	private String mobileLocation;		// 号码归属
	private String sex;		// 性别
	private String mobileKind;		// 手机型号
	private Integer age;		// 年龄
	private String career;		// 职业
	private String comeFrom;		// 渠道来源
	private Date guestTime;		// 获取时间
	private String adName;		// 广告名称
	private String validStatus;		// 有效性
	private String consumptionStatus;		// 消费
	private String mediaUrl;		// 媒体页URL
	private String mediaAdId;		// 媒体广告位ID率
	private String toGroundUrl;		// 落地页URL
	private Long stopTime;		// 停留时间（秒）
	private String message;		// 留言内容
	
	public Ad ad;
	private AdVertiser adVertiser;		// 广告主
	public String audioUploadId;	//音频文件
	
	public AdGuest() {
		this(null);
	}

	public AdGuest(String id){
		super(id);
	}

	@Length(min=0, max=64, message="广告id长度不能超过 64 个字符")
	public String getAdId() {
		return adId;
	}

	public void setAdId(String adId) {
		this.adId = adId;
	}
	
	@Length(min=0, max=64, message="广告主长度不能超过 64 个字符")
	public String getAdVertiserId() {
		return adVertiserId;
	}

	public void setAdVertiserId(String adVertiserId) {
		this.adVertiserId = adVertiserId;
	}
	
	@Length(min=0, max=20, message="联系电话长度不能超过 20 个字符")
	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	
	@Length(min=0, max=255, message="号码归属长度不能超过 255 个字符")
	public String getMobileLocation() {
		return mobileLocation;
	}

	public void setMobileLocation(String mobileLocation) {
		this.mobileLocation = mobileLocation;
	}
	
	@Length(min=0, max=1, message="性别长度不能超过 1 个字符")
	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}
	
	@Length(min=0, max=64, message="手机型号长度不能超过 64 个字符")
	public String getMobileKind() {
		return mobileKind;
	}

	public void setMobileKind(String mobileKind) {
		this.mobileKind = mobileKind;
	}
	
	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}
	
	@Length(min=0, max=100, message="职业长度不能超过 100 个字符")
	public String getCareer() {
		return career;
	}

	public void setCareer(String career) {
		this.career = career;
	}
	
	@Length(min=0, max=64, message="渠道来源长度不能超过 64 个字符")
	public String getComeFrom() {
		return comeFrom;
	}

	public void setComeFrom(String comeFrom) {
		this.comeFrom = comeFrom;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	public Date getGuestTime() {
		return guestTime;
	}

	public void setGuestTime(Date guestTime) {
		this.guestTime = guestTime;
	}
	
	@Length(min=0, max=300, message="广告名称长度不能超过 300 个字符")
	public String getAdName() {
		return adName;
	}

	public void setAdName(String adName) {
		this.adName = adName;
	}
	
	@Length(min=0, max=64, message="有效性长度不能超过 64 个字符")
	public String getValidStatus() {
		return validStatus;
	}

	public void setValidStatus(String validStatus) {
		this.validStatus = validStatus;
	}
	
	@Length(min=0, max=64, message="消费长度不能超过 64 个字符")
	public String getConsumptionStatus() {
		return consumptionStatus;
	}

	public void setConsumptionStatus(String consumptionStatus) {
		this.consumptionStatus = consumptionStatus;
	}
	
	public Integer getAge_gte() {
		return sqlMap.getWhere().getValue("age", QueryType.GTE);
	}

	public void setAge_gte(Integer age) {
		sqlMap.getWhere().and("age", QueryType.GTE, age);
	}
	
	public Integer getAge_lte() {
		return sqlMap.getWhere().getValue("age", QueryType.LTE);
	}

	public void setAge_lte(Integer age) {
		sqlMap.getWhere().and("age", QueryType.LTE, age);
	}
	
	public Date getGuestTime_gte() {
		return sqlMap.getWhere().getValue("guest_time", QueryType.GTE);
	}

	public void setGuestTime_gte(Date guestTime) {
		sqlMap.getWhere().and("guest_time", QueryType.GTE, guestTime);
	}
	
	public Date getGuestTime_lte() {
		return sqlMap.getWhere().getValue("guest_time", QueryType.LTE);
	}

	public void setGuestTime_lte(Date guestTime) {
		sqlMap.getWhere().and("guest_time", QueryType.LTE, guestTime);
	}

	public void setAd_id_gte(){
		if(this.getAd()!=null){
			if(StringUtils.isNotEmpty(this.getAd().getId())){
				sqlMap.getWhere().and("ad_id", QueryType.GTE, this.getAd().getId());
			}
		}

	}


	public Ad getAd() {
		return ad;
	}

	public void setAd(Ad ad) {
		this.ad = ad;
	}

	public AdVertiser getAdVertiser() {
		return adVertiser;
	}

	public void setAdVertiser(AdVertiser adVertiser) {
		this.adVertiser = adVertiser;
	}
	
    
	@Length(min=0, max=255, message="媒体页URL长度不能超过 255 个字符")
	public String getMediaUrl() {
		return mediaUrl;
	}

	public void setMediaUrl(String mediaUrl) {
		this.mediaUrl = mediaUrl;
	}
	
	@Length(min=0, max=255, message="媒体广告位ID率长度不能超过 255 个字符")
	public String getMediaAdId() {
		return mediaAdId;
	}

	public void setMediaAdId(String mediaAdId) {
		this.mediaAdId = mediaAdId;
	}
	
	@Length(min=0, max=255, message="落地页URL长度不能超过 255 个字符")
	public String getToGroundUrl() {
		return toGroundUrl;
	}

	public void setToGroundUrl(String toGroundUrl) {
		this.toGroundUrl = toGroundUrl;
	}
	
	public Long getStopTime() {
		return stopTime;
	}

	public void setStopTime(Long stopTime) {
		this.stopTime = stopTime;
	}
	
	@Length(min=0, max=1024, message="留言内容长度不能超过 1024 个字符")
	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getAudioUploadId() {
		return audioUploadId;
	}

	public void setAudioUploadId(String audioUploadId) {
		this.audioUploadId = audioUploadId;
	}
	
	
}